package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduCheckinRecordMapper;
import com.zenith.edu.po.domain.EduCheckinRecord;
import com.zenith.edu.po.dto.EduCheckinRecordDTO;
import com.zenith.edu.po.vo.EduCheckinRecordVO;
import com.zenith.edu.service.EduCheckinRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduCheckinRecordServiceImpl extends ServiceImpl<EduCheckinRecordMapper, EduCheckinRecord> implements EduCheckinRecordService {
    
    @Override
    public EduCheckinRecordVO createCheckinRecord(EduCheckinRecordDTO dto) {
        EduCheckinRecord checkinRecord = new EduCheckinRecord();
        BeanUtils.copyProperties(dto, checkinRecord);
        this.save(checkinRecord);
        
        EduCheckinRecordVO vo = new EduCheckinRecordVO();
        BeanUtils.copyProperties(checkinRecord, vo);
        return vo;
    }
    
    @Override
    public EduCheckinRecordVO getCheckinRecordById(Long id) {
        EduCheckinRecord checkinRecord = this.getById(id);
        if (checkinRecord == null) {
            return null;
        }
        
        EduCheckinRecordVO vo = new EduCheckinRecordVO();
        BeanUtils.copyProperties(checkinRecord, vo);
        return vo;
    }
    
    @Override
    public EduCheckinRecordVO updateCheckinRecord(EduCheckinRecordDTO dto) {
        EduCheckinRecord checkinRecord = new EduCheckinRecord();
        BeanUtils.copyProperties(dto, checkinRecord);
        this.updateById(checkinRecord);
        
        EduCheckinRecordVO vo = new EduCheckinRecordVO();
        BeanUtils.copyProperties(checkinRecord, vo);
        return vo;
    }
    
    @Override
    public boolean deleteCheckinRecord(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduCheckinRecordVO> getCheckinRecordList() {
        List<EduCheckinRecord> checkinRecordList = this.list();
        return checkinRecordList.stream().map(checkinRecord -> {
            EduCheckinRecordVO vo = new EduCheckinRecordVO();
            BeanUtils.copyProperties(checkinRecord, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}